#include "ExePackHelper.h"

ExePackHelper::ExePackHelper(PackagerUI *mpUI,
                             PrePackage *MPrePackage,
                             QString mCurrentMdlPath,
                             QString mProjectPath,
                             QString mProjectRelativePath,
                             QMap<int, DCCInfo *> *mDCCInfoMap,
                             QString mJarName,
                             QObject *parent):QThread(parent)
{
//    qWarning()<<mDirPath<<endl;
//    qWarning()<<mCurrentMdlPath<<endl;
//    qWarning()<<mProjectPath<<endl;
//    qWarning()<<mProjectRelativePath<<endl;
//    qWarning()<<QString::number(mDCCInfoMap->size())<<endl;
//    qWarning()<<mJarName<<endl;

    this->pUI = mpUI;
    this->currentMdlPath = mCurrentMdlPath;
    this->ProjectPath = mProjectPath;
    this->ProjectRelativePath = mProjectRelativePath;
    this->DCCInfoMap = mDCCInfoMap;
    this->JarName = mJarName;
    this->mPrePackage = MPrePackage;
    emit sendInfoStr(tr("begin preparing files..."));
}

void ExePackHelper::run(){

    if(mPrePackage->initDirPath()){
        emit sendInfoStr(tr("Init direction path successfully！"));
    }else{
        emit sendInfoStr(tr("Init direction path error."));
        return;
    }

    if(mPrePackage->PreMdl(this->currentMdlPath)){
        emit sendInfoStr(tr("Prepare Mdl successfully."));
    }else{
        emit sendInfoStr(tr("Prepare Mdl error."));
        return ;
    }

    if(mPrePackage->PreProject(this->ProjectPath,this->ProjectRelativePath)){
        emit sendInfoStr(tr("prepare project successfully！"));
    }else{
        return ;
    }

    if(mPrePackage->PreConversionMethods(this->DCCInfoMap)){
        emit sendInfoStr(tr("prepare conversion methods successfully！"));
    }else{
        emit sendInfoStr(tr("prepare conversion methods error."));
        return ;
    }

    if(mPrePackage->PreFilesInTable()){
        emit sendInfoStr(tr("prepare files in table successfully！"));
    }else{
        emit sendInfoStr(tr("prepare files in table error."));
        return ;
    }

    if(mPrePackage->PreModelRunLib()){
        emit sendInfoStr(tr("prepare model library successfully！"));
    }else{
        emit sendInfoStr(tr("prepare model library error."));
        return ;
    }

    if(mPrePackage->PreLicense()){
       emit sendInfoStr(tr("prepare license successfully！"));
    }else{
       emit sendInfoStr(tr("prepare license error."));
        return ;
    }


    QString testifyFileStr = "";
    for(int index=0;index<pUI->TestDataList->rowCount();index++){
        if(pUI->TestDataList->columnCount()==2){
            testifyFileStr+="testify/"+pUI->TestDataList->item(index,0)->text()+" ";
        }
      }
    if(mPrePackage->PrePackageConfig("127.0.0.1",
                                  "6000",
                                  "java",
                                  "model/"+this->JarName+".jar",
                                  "model/"+QDir(this->currentMdlPath).dirName(),
                                  testifyFileStr)){
        emit sendInfoStr(tr("prepare Package Config successfully！"));
        testifyFileStr="";
      }else{
         emit sendInfoStr(tr("prepare Package Config error."));
        return ;
    }

    if(mPrePackage->PreJar(this->JarName)){
        emit sendInfoStr(tr("prepare jar successfully！"));
    }else{
        emit sendInfoStr(tr("prepare jar error."));
        return ;
    }
     emit sendInfoStr(tr("ready to save zip."));
     emit open_Zip_window();



}

